﻿using System;
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Phone.Controls;

namespace DBFM7.View
{
    /// <summary>
    /// copyright:kklldog
    /// date:2011-08-29
    ///  qq:17014842
    /// </summary>
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Messenger.Default.Register<string>(this, MsgAction);
        }



        private void About_Click(object sender, EventArgs e)
        {
            MessageBox.Show("豆瓣电台 for WP7\n作者:kklldog\nQQ:17014842\n免责声明：本软件为个人学习所用，" +
                            "不做任何商业用途！系统中部分图片来自互联网，如本软件的下载者复制分发销售获利都跟" +
                            "作者无关！\nLicense: GNU General Public License v 2", "关于", MessageBoxButton.OK);
        }

        private void MsgAction(string str="")
        {
            this.AlubmImage.Opacity = 0;
            this.AlubmImage_Copy.Opacity = 0;
            SongNameMarquee();
        }


        /// <summary>
        /// 歌曲名称滚动
        /// </summary>
        private void SongNameMarquee()
        {
            this.CavSongName.Width = 360;
            this.sb.Stop();
            double sysWidth = System.Windows.Application.Current.Host.Content.ActualWidth;//屏幕宽度
            if (sysWidth <= this.SongName.ActualWidth)
            {
                animation.From = sysWidth;
                animation.To = -this.SongName.ActualWidth - (sysWidth - 360) / 2;//360为Canvas宽度
                this.sb.Begin();
            }
            else
            {//canvas居中
                this.SongName.SetValue(Canvas.LeftProperty, 180 - this.SongName.ActualWidth / 2);
            }

        }

        private void SongName_Loaded(object sender, RoutedEventArgs e)
        {
            SongNameMarquee();
        }

        private SlideTransition st = null;
        /// <summary>
        /// 专辑画出效果
        /// </summary>
        private void ImageChange()
        {
            if (st == null)
            {
                st = new SlideTransition();
            }
            st.Mode = SlideTransitionMode.SlideLeftFadeIn;
            ITransition transition = st.GetTransition(this.AlubmImage_Double);
            transition.Completed += delegate
            {
                transition.Stop();
            };
            transition.Begin();
        }

        private void AlubmImage_ImageOpened(object sender, RoutedEventArgs e)
        {
            this.AlubmImage.Opacity = 1;
            this.AlubmImage_Copy.Opacity = 0.3;
            ImageChange();
        }
    }
}